- target_user = @service.person
- content_for :javascript do
  initialize_update_profile_info_form("#{I18n.locale}","#{target_user.id.to_s}", #{@current_community.real_name_required?});

- content_for :extra_javascript do
  - maps_key = MarketplaceHelper.google_maps_key(@current_community.id)
  - key_param = maps_key ? "?key=#{maps_key}" : ""
  - needs_maps = !FeatureFlagHelper.feature_enabled?(:topbar_v1) || search_mode == :keyword
  = javascript_include_tag "//maps.googleapis.com/maps/api/js#{key_param}" if needs_maps

- content_for :title_header do
  %h1= t("layouts.no_tribe.settings")

- if @service.admin_acts_as_person?
  - content_for :banner_warning do
    = t('settings.profile.editing_profile_of', name: target_user.full_name)

= render :partial => "layouts/left_hand_navigation", :locals => { :links => settings_links_for(target_user, @current_community, @service.admin_acts_as_person?) }

#person_settings_form.left-navi-section.settings-section
  %p
    = t("settings.profile.these_fields_are_shown_in_your")
    = link_to(t("settings.profile.profile_page"), target_user) + "."

  = form_for target_user do |form|
    = hidden_field_tag :referer_form, 'settings'
    = form.label :given_name, t("settings.profile.given_name")
    = form.text_field :given_name, :class => "text_field", :maxlength => "30"
    .inline-label-container
      = form.label :family_name, t("settings.profile.family_name"), :class => "inline"
      %small
        - if ["first_name_with_initial", "first_name_only"].include? @current_community.name_display_type
          = t("settings.profile.#{@current_community.name_display_type}")
    = form.text_field :family_name, :class => "text_field", :maxlength => "30"

    -# Display name
    .inline-label-container
      = form.label :display_name, t("settings.profile.display_name"), class: "inline"
    %span.alert-box-icon
      = icon_tag("information", ["icon-fix"])
    %small
      = t("settings.profile.display_name_description")
    = form.text_field :display_name, class: "text_field", :maxlength => "100"

    -# username
    .inline-label-container
      = form.label :display_name, t("settings.profile.username"), class: "inline"
    %span.alert-box-icon
      = icon_tag("information", ["icon-fix"])
    %small
      = t("settings.profile.username_description")
    = form.text_field :username, class: "text_field", required: true,
      minlength: 3, maxlength: 20, valid_username: true,
      remote: check_username_availability_person_path(target_user.username),
      data: {'msg-remote': t('errors.messages.username_is_invalid')},
      'data-msg-valid_username': t('errors.messages.username_is_invalid')

    -# Location
    - if show_location?
      .inline-label-container
        = form.label :street_address, t("settings.profile.street_address"), :class => "inline"
        %small
          = t('settings.profile.default_in_listing')
      %span.alert-box-icon
        = icon_tag("information", ["icon-fix"])
      %small
        = t("settings.profile.location_description")
      = form.text_field :street_address, :class => "text_field", :onkeyup => "timed_input(this)"
      #settings_map_canvas.map
        - content_for :extra_javascript do
          :javascript
            source = document.getElementById("person_street_address");
            $(document).ready(function(){
              googlemapMarkerInit("settings_map_canvas","person_location","person_street_address", true, #{tribe_latitude}, #{tribe_longitude});
              });

    -# Phone number
    - show_phone_number = @service.fixed_phone_field?
    - if show_phone_number
      .inline-label-container
        = form.label :phone_number, t("settings.profile.phone_number"), :class => "inline"
        %small
          = t('settings.profile.invisible')
      = form.text_field :phone_number, :class => "text_field", :maxlength => "25"

    -# Profile picture
    .inline-label-container
      = form.label :image, t("settings.profile.profile_picture")
    %span.alert-box-icon
      = icon_tag("information", ["icon-fix"])
    %small
      = t("settings.profile.profile_picture_description")
    = render 'layouts/filename', file_field: target_user.image
    = form.file_field :image, :size => 30, :id => "avatar_file"

    -# About text
    = form.label :description, t("settings.profile.about_you"), :class => "input"
    %span.alert-box-icon
      = icon_tag("information", ["icon-fix"])
    %small
      - markdown_popup_link = link_to t("settings.profile.format_markdown_link"), "#", id: "markdown-popup-link"
      = raw t("settings.profile.format_markdown", link: markdown_popup_link)

    = form.text_area :description, :class => "update_profile_description_text_area"
    = form.fields_for :location do |loc|
      = loc.hidden_field :address, :value => target_user.location.address
      = loc.hidden_field :google_address, :value => target_user.location.google_address
      = loc.hidden_field :latitude, :value => target_user.location.latitude
      = loc.hidden_field :longitude, :value => target_user.location.longitude
    - if @service.has_person_custom_fields?
      - @service.custom_field_values.each_with_index do |custom_field_value, index|
        .inline-label-container
        - custom_field = custom_field_value.question
        - custom_field.with_type do |field_type|
          - prefix = "person[custom_field_values_attributes][]"
          .inline-label-container
            = label "person_custom_fields", index, "#{custom_field.name(I18n.locale)}#{custom_field.required ? '*' : ''}",
              class: 'inline'
            - if custom_field.public?
              %small= t('settings.profile.shown_in_your_public_profile')
          = hidden_field_tag "#{prefix}[id]", custom_field_value.id
          = hidden_field_tag "#{prefix}[type]", custom_field_value.type
          = hidden_field_tag "#{prefix}[custom_field_id]", custom_field_value.custom_field_id
          = render "settings/custom_fields/#{field_type}", :service => @service,
            :custom_field => custom_field, index: index,
            :custom_field_value => custom_field_value,
            :prefix => prefix
    = form.button t("settings.save_information"), :class => "send_button"

= render :partial => 'layouts/markdown_help'
